using System;
using System.ComponentModel;

namespace teavch.Utilities.Electrical.Design.Gui.LineDiagram
{
	public partial class Connector : ElectricalSymbol
	{

		private float _handRatio = .5f;

		public Connector()
		{
			InitializeComponent();
		}

		[Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the Top Link Line ration of the top node of the Transformer" )]
		public float HandRatio
		{
			get { return this._handRatio; }
			set
			{
				this._handRatio = value;
				this.Refresh();
			}
		}

		protected override void OnPaint( System.Windows.Forms.PaintEventArgs e )
		{
			base.OnPaint( e );
			this.Paint( e );
		}

		protected override void OnResize( EventArgs e )
		{
			base.OnResize( e );
			ResizeNow( e );
		}

		private void ResizeNow( EventArgs ea )
		{
			this.Refresh();
		}

		private new void Paint( System.Windows.Forms.PaintEventArgs pea )
		{
			float c1x1 = 0, c1y1 = 0, c1size = 0;

			float l1x1 = 0, l1y1 = 0, l1x2 = 0, l1y2 = 0;

			c1size = this.SymbolSize;

			l1x1 = c1size / 2 ;
			l1y1 = 0;
			l1x2 = l1x1;
			l1y2 = c1size * this._handRatio;

			c1x1 = 0;
			c1y1 = l1y2;

			this.Height = ( int ) Math.Ceiling( c1y1 + c1size + 1 );
			this.Width = ( int ) Math.Ceiling( c1size + 1 );
			
			System.Drawing.Drawing2D.PathGradientBrush _gBrush = null;
			System.Drawing.Drawing2D.GraphicsPath _gpath = new System.Drawing.Drawing2D.GraphicsPath();

			_gpath.AddArc( c1x1, c1y1, c1size, c1size, 0, 360 );
			if ( this.Fill == true )
			{
				_gBrush = new System.Drawing.Drawing2D.PathGradientBrush( _gpath );
				_gBrush.CenterColor = this.Parent.BackColor;
				_gBrush.SurroundColors = new System.Drawing.Color[] { this.State == SymbolState.On ? System.Drawing.Color.Red : System.Drawing.Color.Lime };
				_gBrush.WrapMode = System.Drawing.Drawing2D.WrapMode.TileFlipY;
				pea.Graphics.FillPath( _gBrush, _gpath );
			}
			_gpath.CloseFigure();
			_gpath.AddLine( l1x1, l1y1, l1x2, l1y2 );
			pea.Graphics.DrawPath( this.Pen, _gpath );
			
		}

	}
}
